package com.drug.service.impl;

import com.drug.domain.Combine;
import com.drug.domain.Result;
import com.drug.domain.ReturnGoods;
import com.drug.mapper.*;
import com.drug.service.ReturnorderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReturnorderServiceImpl implements ReturnorderService {

    @Autowired
    private ReturnGoodsMapper returnGoodsMapper;
    @Override
    public Result findAllReturnGoods(Combine combine) {
        Integer pageNum=1;
        pageNum  = combine.getPageNum();
        if (pageNum==null){
            pageNum=1;
        }
        PageHelper.startPage(pageNum,5);
        List<ReturnGoods> returnGoods = returnGoodsMapper.selectAll(combine);
        PageInfo pageInfo =new PageInfo(returnGoods);
        Result result = new Result();
        result.setData(pageInfo);
        return result;
    }
    //
    @Override
    public Result updateState(Integer[] ids) {
        Result result =new Result();
        if (ids!=null){
            int a=0;
            for (int i = 0; i < ids.length; i++) {
                a=returnGoodsMapper.updateState1(ids[i]);
                a++;
            }
            int b =ids.length-a;
            result.setMsg("您的操作成功!成功"+a+"条,失败"+b+"条!");
        }else {
            result.setMsg("请选择!!!");
        }

        return result;
    }

    @Override
    public List<ReturnGoods> findAllExport() {
        return  returnGoodsMapper.selectAllExport();

    }

}
